{include file="public/header"}
<body>
	<div class="sectionY">
		<a href="{:url('User/index')}">
			<img src="__PUBLIC__/home/images/a19.png" alt="" class="a1">
		</a>
		<p class="p1">订单</p>
	</div>
	<div class="kong1"></div>
	<div class="ding_section1">
		<div class="container">
			<ul class="clearfix">
				<li {if $type eq 1}class="select"{/if} data-type="1">
					<a href="javascript:;">待付款</a>
				</li>
				<li {if $type eq 2}class="select"{/if} data-type="2">
					<a href="javascript:;">待收货</a>
				</li>
				<li {if $type eq 3}class="select"{/if} data-type="3">
					<a href="javascript:;">已完成</a>
				</li>
				<li {if $type eq 4}class="select"{/if} data-type="4">
					<a href="javascript:;">已取消</a>
				</li>
			</ul>
		</div>
	</div>
	<div class="ding_section2">
		<div class="t1 ulData" style="display: block;">

		</div>
		<div style="line-height: 25px; text-align: center; color: #868686;" onclick="loadData()" class="more">
			<span style="width: 100%;">--点击查看更多--</span>
		</div>
	</div>
</body>
<script>
	$(function(){
		$(".ding_section1 li").click(function(){
			$(this).addClass("select").siblings().removeClass("select");
			var type = $(this).data("type");
			query.type=type;
			query.page=1;
			is_end=false;
			loadData();
			// $(".ding_section2 .t1").eq(dd).show().siblings().hide()
		})
		loadData();
		//取消订单
		$(".ulData").on("click", ".cancelOrder", function (e) {
			let order_id = $(this).data("order_id"),o=this;
			modal.confirm("确定取消订单？", "确定", function () {
				$.post("{:url('cancelOrder')}", {order_id:order_id}, function (res) {
					modal.msg(res.result_info);
					if(res.result_code==0){
						$(o).parents(".f1").remove();
					}
				});
			})
		})
		//去支付
		$(".ulData").on("click", ".payOrder", function (e) {
			let order_id = $(this).data("order_id");
			location.href="{:url('payInfo')}?order_id="+order_id;

		})
		//确认收获
		$(".ulData").on("click", ".receiveOrder", function (e) {
			let order_id = $(this).data("order_id");
			modal.confirm("确定收获？", "确定", function () {
				$.post("{:url('receiveOrder')}", {order_id:order_id}, function (res) {
					modal.msg(res.result_info);
					if(res.result_code == 0){
						$(o).parents(".f1").remove();
					}
				});
			})

		})
		//去评价
		$(".ulData").on("click", ".goComment", function (e) {
			let order_id = $(this).data("order_id");
			location.href="{:url('goComment')}?order_id="+order_id;
		})

	})
	var query={
		page:1,
		page_num:20,
		type:{$type}
	},is_end=false;
	//加载数据
	function loadData() {
		if(is_end){
			return;
		}
		let index = modal.loading();
		$.post("{:url('getOrderList')}", query, function (res) {
			if(query.page==1){
				$(".ulData").html("");
			}
			query.page++;
			modal.close(index);
			modal.msg(res.result_info);
			let data = res.result_data;
			// console.log(data);
			// return;
			if(res.result_code==0){
				let _li = '';
				$.each(data, function (i,v) {
					_li += '\t\t\t<div class="f1">\n' +
							'\t\t\t\t<div class="title">\n' +
							'\t\t\t\t\t<p class="p1">订单号：'+v.order_sn+'</p>\n' +
							'\t\t\t\t</div>\n';
					$.each(v.data, function (i1,v1) {
						_li += '\t\t\t\t<div class="center clearfix"  onclick="goDetail('+v.id+')">\n' +
								'\t\t\t\t\t<div class="logo">\n' +
								'\t\t\t\t\t\t<img src="'+v1.img_url+'" alt="">\n' +
								'\t\t\t\t\t</div>\n'+
								'\t\t\t\t\t<div class="list">\n' +
								'\t\t\t\t\t\t<p class="p1 chao2">'+v1.title+'-'+v1.spec_title+'</p>\n' +
								'\t\t\t\t\t</div>\n' +
								'\t\t\t\t</div>\n';
					});
					_li +='\t\t\t\t<div class="last">\n' +
							'\t\t\t\t\t<p class="p1">共'+v.num+'件商品，实付款：<span class="s1">￥'+v.money+'</span></p>\n' +
							'\t\t\t\t</div>\n' +
							'\t\t\t\t<div class="next">\n';
					if(v.order_status==0){
						_li += '\t\t\t\t\t<a href="javascript:;" data-order_id="'+v.id+'" class="a1 cancelOrder">取消订单</a>\n' +
								'\t\t\t\t\t<a href="javascript:;" data-order_id="'+v.id+'" class="a2 payOrder">去付款</a>\n';
					}
					if(v.order_status==1 || v.order_status==2){
						_li += '<a href="javascript:;" data-order_id="'+v.id+'" class="a2 receiveOrder">确认收货</a>'
					}
					if(v.order_status==3){
						_li += '<a href="javascript:;" data-order_id="'+v.id+'" class="a2 goComment">去评价</a>'
					}
					if(v.order_status==5){
						_li += '<a href="javascript:;" class="a2">已完成</a>'
					}
					if(v.order_status==4){
						_li += '<a href="javascript:;" class="a2">已取消</a>'
					}
					_li+=		'\t\t\t\t</div>\n' +
							'\t\t\t\t<div class="ge"></div>\n' +
							'\t\t\t</div>';
				})
				$(".ulData").append(_li);
			}
			if(data.length<query.page_num){
				$(".more").find("span").text("--我是有底线的--");
				is_end=true;
			}
		});
	}
	function goDetail(order_id) {
		location.href="{:url('Order/orderDetail')}?order_id="+order_id;
	}

</script>

</html>